<?php 
$mon = $this->common_model->getdata('subjects',array('publish'=>1,'parentid !='=>0),array('id','title'));
$userid = $this->session->userdata('id');
$alias = preg_replace("/(.html)/",'', $this->security->xss_clean($this->uri->segment(1,0)));
$idusser = substr($alias,17);
?>
<style>
.noTitleStuff .ui-dialog-titlebar {display:none}
label.title{display:block;text-align:right;float:left;min-width: 120px;margin-right: 10px;font-weight:bold;}
label.content{display:block;text-align:left;float:left;margin-left: 10px;}
p.roww{height:40px;width:400px}
p.roww input{width:170px;height:30px;line-height:inherit}
.ui-dialog{width:40%;height:350px;position:fixed;top: 18%;left:25%;border-radius: 10px;}
</style>
<div class="lean_overlay overlay hidden">&nbsp;</div>
<div id="success_new" style="display:none">
</div>
<h3 class="title_sent"><i class="icon-envelope"></i>Email cho <?php echo $details->name; ?></h3>
<div class="tong">
	<!-- /.title_sent -->
	<p class="intro_email">Để gửi email cho gia sư xin phụ huynh hoặc học sinh vui lòng nhập  theo mẫu Form bên dưới</p>
		<form name="form_mails" id="form_mails" action="<?php echo base_url(); ?>ajax/guiemail" method="post">
		<input id="tutor_id" type="hidden" name="tutor_id" value="<?php echo $idusser;?>" />
		<div class="form_sent">
			 <p class="title1">Nội dung</p>
			<textarea <?php if($userid == $idusser && $userid != ''){echo 'disabled';} ?> id="des_email" class="arena noidung text_box1" name="des_email"></textarea>
			<!-- /.arena -->
			<p class="title1">Môn học</p>
			<input <?php if($userid == $idusser && $userid != ''){echo 'disabled';} ?> id="subjects" type="text" class="text_box1 subjects" name="subjects" placeholder="VD : Vật lí" />
			<?php if(!$userid){ ?>
            <div class="inline_input">
				<p class="title1">Họ và tên</p>
				<input type="text" class="name text_box1" id="name" name="name" />
			</div>
            <p class="title1">Điện thoại</p>
			<input type="text" class="input phone text_box1 style_100" id="phone" name="phone" />
			<p class="title1">Email</p>
			<input type="text" class="input email text_box1 style_100" id="email" name="email" />			
            <?php } ?>
		</div>
		<!-- /.form_sent -->
        <div class="node">
        </div>
		<a id="sent_mails" class="btn_details sent_mails" title="Gửi"><i class="icon-envelope"></i>&nbsp;&nbsp;Gửi email</a>
		</form>
</div>
<script>
$(document).ready(function(){
	$('.gopy').click(function(){
		$('body').prepend('<div class="overlay">&nbsp;</div>')
		$('#success_new').fadeIn(400);
	});
	$('div.overlay').click(function(){
		$('#success_new').slideUp(400);
		$('.overlay').remove();
	});
	$('.close1,.close-over').click(function(){
		$('#success_new').slideUp(400);
		$('.overlay').remove();
	});

	var form = $("#form_mails").submit(function(e){
		var mailData = $(this).serializeArray();
		var mailURL = $(this).attr("action");
		$.ajax({
			url: mailURL,
			type: "POST",
			data: mailData,
			success: function(data, textStatus, jqXHR){
				if(data.success == true){
					$('.loading').remove();
					$('.node').remove();
					$('#success_new').html(data.content);
					$("#success_new").dialog({
						width: '40%', 
						modal: true, 
						dialogClass: 'noTitleStuff',
						resizable: false
					});
				}
				else{
					$('.loading').remove();
					$('.node').html(data.content);
				}
			},
		});
		e.preventDefault();
		e.unbind();
	});
	$("#sent_mails").on('click',function(){
		$('.form_sent').append('<div class="loading"><i class="icon-spinner icon-spin icon-large"></i> Đang tải dữ liệu vui lòng đợi...</div>');
		form.submit();
	});
});
</script>
<script>
$(document).ready(function() {
var availableTags = [<?php if(!empty($mon)){
    $i=0;
    $n=count($mon);
    foreach($mon as $mon){
        if($i==$n){
            echo '"'.$mon->title.'"';
        }else{
            echo '"'.$mon->title.'",';
        }
        
        $i++;
    }
}?>
  
];
$( ".subjects" ).autocomplete({
  source: availableTags,disabled: false,autoFocus:true,widget:true,delay:0
});
});
</script>
